﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PPI.Client;
using PPI.Client.Logic;
using PPI.Client.Utils;
using PPI.Entities;
using VMind.Global;

namespace PPIControls.Map
{
    public partial class GPSInspectionFilters : UserControl
    {
        private List<EVendor> m_Vendors;
        private List<EVendor_Contact> m_Contacts;
        private List<EVendor_Project> m_Projects;


        public GPSInspectionFilters()
        {
            InitializeComponent();
        }

        public void ClearSelectedItems()
        {
            DropdownHelper.ResetComboIndex(lstVendors);
            DropdownHelper.ResetComboIndex(lstContacts);
            DropdownHelper.ResetComboIndex(lstProjects);

        }

        public void LoadList()
        {
            m_Vendors = LCacheDataSingleton.Instance.Vendor;
            DropdownHelper.FillListBox(lstVendors, m_Vendors, typeof(EVendor), "Name", "VendorId", "");

            m_Contacts = LCacheDataSingleton.Instance.Contacts;
            DropdownHelper.FillListBox(lstContacts, m_Contacts, typeof(EVendor_Contact), "Name", "Vendor_ContactId", "");

            m_Projects = LCacheDataSingleton.Instance.Projects;
            DropdownHelper.FillListBox(lstProjects, m_Projects, typeof(EVendor_Project), "Name", "Vendor_ProjectId", "");

        }

        public List<EVendor> SelectedVendors()
        {
            List<EVendor> returnVendorList = new List<EVendor>();

            foreach (ListBoxItem item in lstVendors.SelectedItems)
            {
                returnVendorList.Add(new EVendor(ConvertHelper.ToInt32(item.Value), item.Text, ""));
            }
            return returnVendorList;
        }

        public List<EVendor_Contact> SelectedContacts()
        {
            List<EVendor_Contact> returnContactList = new List<EVendor_Contact>();

            foreach (ListBoxItem item in lstContacts.SelectedItems)
            {
                returnContactList.Add(new EVendor_Contact(ConvertHelper.ToInt32(item.Value), item.Text));
            }
            return returnContactList;
        }

        public List<EVendor_Project> SelectedProjects()
        {
            List<EVendor_Project> returnProjectList = new List<EVendor_Project>();

            foreach (ListBoxItem item in lstProjects.SelectedItems)
            {
                returnProjectList.Add(new EVendor_Project(ConvertHelper.ToInt32(item.Value), item.Text));
            }
            return returnProjectList;
        }

    }
}
